package com.wuliu.web.controller.system;

import java.util.List;
import javax.servlet.http.HttpServletResponse;

import com.wuliu.common.annotation.Anonymous;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.security.access.prepost.PreAuthorize;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.wuliu.common.annotation.Log;
import com.wuliu.common.core.controller.BaseController;
import com.wuliu.common.core.domain.AjaxResult;
import com.wuliu.common.enums.BusinessType;
import com.wuliu.system.domain.SysAccount;
import com.wuliu.system.service.ISysAccountService;
import com.wuliu.common.utils.poi.ExcelUtil;
import com.wuliu.common.core.page.TableDataInfo;

/**
 * 帐套Controller
 *
 * @author ruoyi
 * @date 2023-09-23
 */
@Api(tags = {"账套管理控制器"})
@RestController
@RequestMapping("/system/account")
public class SysAccountController extends BaseController {
    @Autowired
    private ISysAccountService sysAccountService;

    /**
     * 查询帐套列表
     */
    @ApiOperation(value = "查询账套")
    @PreAuthorize("@ss.hasPermi('system:account:list')")
    @GetMapping("/list")
    public TableDataInfo list(SysAccount sysAccount) {
        startPage();
        List<SysAccount> list = sysAccountService.selectSysAccountList(sysAccount);
        return getDataTable(list);
    }

    /**
     * 导出帐套列表
     */
    @ApiOperation(value = "导出账套")
    @PreAuthorize("@ss.hasPermi('system:account:export')")
    @Log(title = "帐套", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, SysAccount sysAccount) {
        List<SysAccount> list = sysAccountService.selectSysAccountList(sysAccount);
        ExcelUtil<SysAccount> util = new ExcelUtil<SysAccount>(SysAccount.class);
        util.exportExcel(response, list, "帐套数据");
    }

    /**
     * 获取帐套详细信息
     */
    @ApiOperation(value = "账套详细")
    @PreAuthorize("@ss.hasPermi('system:account:query')")
    @GetMapping(value = "/{id}")
    public AjaxResult getInfo(@PathVariable("id") String id) {
        return success(sysAccountService.selectSysAccountById(id));
    }

    /**
     * 新增帐套
     */
    @ApiOperation(value = "新增账套")
    @PreAuthorize("@ss.hasPermi('system:account:add')")
    @Log(title = "帐套", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody SysAccount sysAccount) {
        return toAjax(sysAccountService.insertSysAccount(sysAccount));
    }

    /**
     * 修改帐套
     */
    @ApiOperation(value = "修改账套")
    @PreAuthorize("@ss.hasPermi('system:account:edit')")
    @Log(title = "帐套", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody SysAccount sysAccount) {
        return toAjax(sysAccountService.updateSysAccount(sysAccount));
    }

    /**
     * 删除帐套
     */
    @ApiOperation(value = "删除账套")
    @PreAuthorize("@ss.hasPermi('system:account:remove')")
    @Log(title = "帐套", businessType = BusinessType.DELETE)
    @DeleteMapping("/{ids}")
    public AjaxResult remove(@PathVariable String[] ids) {
        return toAjax(sysAccountService.deleteSysAccountByIds(ids));
    }

    @Anonymous
    @GetMapping("/getAll")
    public TableDataInfo getAll() {
        List<SysAccount> list = sysAccountService.selectSysAccountList(new SysAccount());
        return getDataTable(list);
    }
}
